import 'package:flutter/material.dart';
import 'pages/tabs.dart';
import './pages/tabs/index.dart';
import './pages/tabs/my.dart';

import './routers/routers.dart';


void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {


  const MyApp({Key? key}) : super(key: key); //const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      //关闭顶部的debug标签
      debugShowCheckedModeBanner: false,
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.green,
      ),
      // home: const HomePage(),
      //2、命名路由
      initialRoute: '/', //初始启动页面路由。前面已经定义了'/'对应homePage()
      //3、命名路由传参使用这个函数(使用命令路由跳转时，都会触发这个函数)
      onGenerateRoute:onGenerateRoute
    );
  }
}

class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  _MainState createState() => _MainState();
}

class _MainState extends State<HomePage> {
  //---------底部tabBar相关---------
  final List<Widget> _pageBodyList = const [Index(), My()];
  //默认Index页面
  Widget curPageBody = const Index();
  //底部tabBar，即组件bottomNavigationBar回调函数.参数是点的底部tabBar后，获取的tabBar索引
  switchBottomNavigationBar(activeIndex) {
    setState(() {
      curPageBody = _pageBodyList[activeIndex];
    });
  }

  //生命周期函数：build。此方法用于渲染界面。 setState函数中用于设置数据，会重新执行build
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      //顶部bar
      appBar: AppBar(
        //顶部bar--标题
        title: const Text('测试12'),
        elevation:0,
        //顶部bar--右侧按钮
        actions: [
          IconButton(
              onPressed: () {
                print(1);
              },
              icon: const Icon(Icons.search))
        ],
        //顶部bar下的滑动tab。
      ),
      //中间主体区域
      body: curPageBody,
      //左侧抽屉
      drawer: const Drawer(
          child: Column(
        children: [
          UserAccountsDrawerHeader(
              currentAccountPicture: CircleAvatar(
                backgroundImage:
                    NetworkImage('https://heyingjiee.github.io/logo.png'),
              ),
              decoration: BoxDecoration(color: Colors.blue),
              accountName: Text('张三'),
              accountEmail: Text('125351241@xx.com')),
          ListTile(
            leading: CircleAvatar(child: Icon(Icons.access_alarm_outlined)),
            title: Text('定时器'),
          ),
          Divider(),
          ListTile(
            leading:
                CircleAvatar(child: Icon(Icons.account_balance_wallet_sharp)),
            title: Text('钱包'),
          )
        ],
      )),
      //底部tabBar
      bottomNavigationBar:
          Tabs(switchBottomNavigationBar: switchBottomNavigationBar),
      //浮动按钮
      floatingActionButton: Container(
        width: 60,
        height: 60,
        padding: const EdgeInsets.all(5),
        margin: const EdgeInsets.only(top: 10),
        decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(1000),
            color: const Color(0xEEEEEEEE)),
        child: FloatingActionButton(
          child: const Icon(Icons.view_in_ar),
          onPressed: () {},
        ),
      ),
      //浮动按钮定位
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
    );
  }
}
